<?php

namespace app\api\controller;

use app\api\service\TrainService;
use app\api\validate\TrainValidate;

class Train extends Base
{
    protected $middleware = ['NotFoundMiddleware'];

    /**
     * 获取今日训练
     * @needLogin True
     * @method GET
     * @return void
     */
    public function getUserTrain()
    {
//        if (($msg = VideoValidate::getVideoList($this->params)) !== true) apiReturn(201, $msg);
        list($code, $msg, $data) = TrainService::getUserTrain($this->_user_info, $this->params);
        apiReturn($code, $msg, $data);
    }

    /**
     * 获取训练详情
     * @needLogin True
     * @method GET
     * @return void
     */
    public function getTrainInfo()
    {
        if (($msg = TrainValidate::getTrainInfo($this->params)) !== true) apiReturn(201, $msg);
        list($code, $msg, $data) = TrainService::getTrainInfo($this->_user_info, $this->params);
        apiReturn($code, $msg, $data);
    }

    /**
     * 获取训练记录
     * @needLogin True
     * @method GET
     * @return void
     */
    public function getTrainRecord()
    {
        if (($msg = TrainValidate::getTrainRecord($this->params)) !== true) apiReturn(201, $msg);
        list($code, $msg, $data) = TrainService::getTrainRecord($this->_user_info, $this->params);
        apiReturn($code, $msg, $data);
    }

    /**
     * 提交训练结果
     * @needLogin True
     * @method POST
     * @return void
     */
    public function saveTrainInfo()
    {
        if (($msg = TrainValidate::saveTrainInfo($this->params)) !== true) apiReturn(201, $msg);
        list($code, $msg, $data) = TrainService::saveTrainInfo($this->_user_info, $this->params);
        apiReturn($code, $msg, $data);
    }
}